import java.util.Scanner;

public class Mang {
    private Laud laud;
    private int kord=0, kes=1;
    private Mangija mangija1;
    private Mangija mangija2;
    public Scanner input = new Scanner(System.in);

    
    public Mang(){
        laud = new Laud();
        alustaMangijatega();
        
        while( Mangi() );
    }
	
	public void alustaMangijatega(){
		System.out.println("Kes on mangija 1 ?");
		if(valiMangija() ==1)
			this.mangija1 = new Inimene(1);
		System.out.println(" V2ga h2sti!!! ");
		System.out.println("Kes on mangija 2 ?");
		
		if(valiMangija() == 1)
			this.mangija2 = new Inimene(2);
	
	}
	public int valiMangija(){
		int valik=0;
		
		do{
			System.out.println("1. Vajuta 1 et kinnitada");
			System.out.println("Valik:  ");
			valik = input.nextInt();
			
			if(valik !=1)
				System.out.println("Vale valik, proovi uuesti");
		}while(valik !=1);
		
		return valik;
	}
	
	public boolean Mangi(){
		laud.naitaLaud();
		if(voit() == 0){
			System.out.println("\nK2ikude arv: "+kord);
			System.out.println("M2ngija "+kes()+" kord");
			if(kes()==1)
				mangija1.mangi(laud);
			else
				mangija2.mangi(laud);
				
			if(laud.t2isLaud()){
				System.out.println("********** Viik ***********");
				return false;
			}
			kes++;
			kord++;
			
			return true;
		}else{
			if(voit() ==-1)
				System.out.println("******** M2ngija 1 v6itis *********");
			else
				System.out.println("******** M2ngija 2 v6itis *********");
				
			return false;
		}
	}
	
	public int kes(){
		if(kes%2 == 1)
			return 1;
		else
			return 2;
	}
	public int voit(){
		if(laud.vaataRida() == 1)
			return 1;
		if(laud.vaataVeerg() == 1)
			return 1;
		if(laud.vaataDiagonaal() == 1)
			return 1;
			
		if(laud.vaataRida() == -1)
			return -1;
		if(laud.vaataVeerg() == -1)
			return -1;
		if(laud.vaataDiagonaal() == -1)
			return -1;
			
		return 0;
	}
}
			
			
			
			
			
			
			
			
			
			
			
			
  